<template>
	<view class="department-container">
		<!-- 头部区域 -->
		<view class="header">
			<view class="title">权限管理</view>
			<view class="subtitle">管理用户权限与权限信息</view>
		</view>

		<!-- 权限列表 -->
		<view class="department-list">
			<view v-for="(item, index) in data" :key="item._id" @click="onclick(item._id)" class="department-item"
				:style="{
					'border-left': `6rpx solid ${index % 3 === 0 ? '#1a73e8' : index % 3 === 1 ? '#00c853' : '#7b1fa2'}`
				}">
				<view class="item-header">
					<uni-icons type="home" size="24"
						:color="index % 3 === 0 ? '#1a73e8' : index % 3 === 1 ? '#00c853' : '#7b1fa2'"
						class="item-icon"></uni-icons>
					<view class="department-name">{{ item.role_name || '未知权限' }}</view>
					<view class="sort-value">
						<uni-icons type="sort" size="14" color="#999"></uni-icons>
						{{ item.role_id != null ? item.role_id : '未设置' }}
					</view>
				</view>

				<view class="item-footer">
					<view :class="['status-badge', item.status == 0 ? 'active' : 'inactive']">
						{{ status[item.status] || '未知状态' }}
					</view>
					<uni-icons type="right" size="18" color="#999"></uni-icons>
				</view>
			</view>
		</view>

		<!-- 空状态 -->
		<view v-if="data.length === 0" class="empty-state">
			<image src="/static/avatar/empty.png" class="empty-image" mode="aspectFit"></image>
			<view class="empty-text">暂无权限数据</view>
			<view class="empty-hint">点击下方按钮添加第一个权限</view>
		</view>

		<!-- 新增按钮 -->
		<uni-fab ref="fab" horizontal="right" vertical="bottom" @fabClick="fabClick" type="plus"
			:button-color="'#1a73e8'" :icon-color="'#fff'" />
	</view>
</template>

<script>
	export default {
		data() {
			return {
				status: {
					0: '正常',
					1: '禁用',
				},
				data: [],
			};
		},
		onShow() {
			this.getpower()
		},

		methods: {
			onclick(e) {
				uni.$router.to({
					url: 'pagesA/admin/power/add',
					params: {
						_id: e,
						type: 'edit'
					}
				})
			},
			async getpower() {
				try {
					const obj = uniCloud.importObject('basedata')
					const res = await obj.getRole({})
					if (res.code == 0) {
						this.data = res.data
					} else {
						uni.showToast({
							title: '获取权限数据失败',
							icon: 'none'
						})
					}
				} catch (err) {
					uni.showToast({
						title: '请求失败，请重试',
						icon: 'none'
					})
				}
			},
			fabClick() {
				uni.$router.to({
					url: 'pagesA/admin/power/add',
				})
			}
		}
	};
</script>

<style lang="scss" scoped>
	/* 整体容器 */
	.department-container {
		background: linear-gradient(180deg, #f0f7ff 0%, #e6f0ff 100%);
		min-height: 100vh;
		padding: 30rpx 20rpx 120rpx;
	}

	/* 头部区域 */
	.header {
		padding: 30rpx 20rpx;
		background: #fff;
		border-radius: 20rpx;
		box-shadow: 0 4rpx 20rpx rgba(26, 115, 232, 0.1);
		margin-bottom: 30rpx;
	}

	.title {
		font-size: 42rpx;
		font-weight: bold;
		color: #1a4e8e;
		display: block;
	}

	.subtitle {
		font-size: 28rpx;
		color: #5a7ea0;
		display: block;
		margin-top: 10rpx;
	}

	/* 权限列表 */
	.department-list {
		background: #fff;
		border-radius: 20rpx;
		overflow: hidden;
		box-shadow: 0 6rpx 20rpx rgba(26, 115, 232, 0.08);
	}

	.department-item {
		padding: 30rpx;
		display: flex;
		flex-direction: column;
		border-bottom: 1rpx solid #f0f7ff;
		background: #fff;
		transition: all 0.3s;
	}

	.department-item:active {
		background-color: #f9fbfe;
	}

	.item-header {
		display: flex;
		align-items: center;
		margin-bottom: 20rpx;
	}

	.item-icon {
		background: rgba(26, 115, 232, 0.1);
		border-radius: 50%;
		padding: 12rpx;
		margin-right: 20rpx;
	}

	.department-name {
		font-size: 34rpx;
		font-weight: 500;
		color: #1a4e8e;
		flex: 1;
	}

	.sort-value {
		font-size: 26rpx;
		color: #5a7ea0;
		display: flex;
		align-items: center;
	}

	.item-footer {
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.status-badge {
		font-size: 26rpx;
		padding: 8rpx 20rpx;
		border-radius: 30rpx;
		font-weight: 500;
	}

	.active {
		background: rgba(0, 200, 83, 0.1);
		color: #00c853;
	}

	.inactive {
		background: rgba(158, 158, 158, 0.1);
		color: #9e9e9e;
	}

	/* 空状态 */
	.empty-state {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		padding: 60rpx 0;
		margin-top: 60rpx;
		background: #fff;
		border-radius: 24rpx;
		box-shadow: 0 6rpx 20rpx rgba(26, 115, 232, 0.08);
	}

	.empty-image {
		width: 200rpx;
		height: 200rpx;
		opacity: 0.7;
	}

	.empty-text {
		font-size: 32rpx;
		color: #1a4e8e;
		margin: 20rpx 0 10rpx;
		font-weight: bold;
	}

	.empty-hint {
		font-size: 26rpx;
		color: #5a7ea0;
	}
</style>